#include "stdafx.h"
#include "Cell.h"
#include "layout.h"
#include "SkCanvas.h"
#include "View.h"

Cell::Cell(unsigned int xInHundred)
	: m_ViewOrLayout(NULL)
	, m_type(TYPE_NOTSET)
	, m_xInHundred(xInHundred)
	, m_id(0)
	, m_leftOrRightPad(0)
	, m_padisLeft(true)
	, m_topOrBottomPad(0)
	, m_padisTop(true)
{
}

Cell::Cell()
	: m_ViewOrLayout(NULL)
	, m_type(TYPE_NOTSET)
	, m_xInHundred(0)
	, m_id(0)
	, m_leftOrRightPad(0)
	, m_padisLeft(true)
	, m_topOrBottomPad(0)
	, m_padisTop(true)
{
}



Cell::~Cell()
{
}

void Cell::SetView(View* view)
{
	m_ViewOrLayout = view;
	m_type = TYPE_VIEW;

	view->setBolder(m_x, m_y, m_width, m_height);
}

void Cell::SetLayout(Layout* layout)
{
	m_ViewOrLayout = layout;
	m_type = TYPE_LAYOUT;
}

bool Cell::GetViewOrLayout(void*& viewOrLayout, enum Type& type)
{
	viewOrLayout = m_ViewOrLayout;
	type = m_type;

	return true;
}

void Cell::updateLayout()
{
	if (m_type == TYPE_VIEW)
	{
		View* view = reinterpret_cast<View*>(m_ViewOrLayout);

		// TODO: Just for test.
		view->setBolder(m_x, m_y, m_width, m_height);

		view->updateLayout();
	}
	else if (m_type == TYPE_LAYOUT)
	{
		Layout* layout = reinterpret_cast<Layout*>(m_ViewOrLayout);
		layout->setRect(m_x, m_y, m_width, m_height);
		layout->updateLayout();
	} 
	else if (m_type == TYPE_NOTSET)
	{
		// Do Nothing
	}
}

bool Cell::onPaint(SkCanvas* pCanvas)
{
	if (m_type == TYPE_VIEW)
	{
		// Not do anything,
	}
	else if (m_type == TYPE_LAYOUT)
	{
		Layout* layout = reinterpret_cast<Layout*>(m_ViewOrLayout);
		return layout->onPaint(pCanvas);
	}
	else if (m_type == TYPE_NOTSET)
	{
		// Do Nothing
	}

	pCanvas->drawRect(SkColor(0, 255, 255, 255), m_x, m_y, m_width-1, m_height-1);

	return true;
}